<?php


namespace App\Repositories;


use App\Models\Dictionary as Model;
use LTools\Repositories\RepositoryAbstract;

class Dictionary extends RepositoryAbstract
{
    /**
     * Dictionary constructor.
     * @param Model $model
     * @author luffyzhao@vip.126.com
     */
    public function __construct(Model $model)
    {
        $this->model = $model;
    }

    /**
     * @param $code
     * @return mixed
     * @author luffyzhao@vip.126.com
     */
    public function search($code){
        $model = $this->find($code);
        return $model->getAttribute('element');
    }

    /**
     * @param array $attributes
     * @return bool|\Illuminate\Database\Eloquent\Model
     * @author luffyzhao@vip.126.com
     */
    public function create(array $attributes = [])
    {
        $attributes['code'] = strtoupper($attributes['code']);
        return parent::create($attributes);
    }

    /**
     * @param $id
     * @param array $values
     * @return bool|\Illuminate\Database\Eloquent\Model
     * @throws \Throwable
     * @author luffyzhao@vip.126.com
     */
    public function update($id, array $values)
    {
        $values['code'] = strtoupper($values['code']);
        return parent::update($id, $values);
    }
}
